home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / programming / mui / mcc_popph / mcc_popph_src / debug.h < prev    next >
C/C++ Source or Header  |  1999-11-30  |  4KB  |  123 lines

  1.  
  2. /*
  3. ** $Id: debug.h,v 1.2 1999/11/16 20:58:11 carlos Exp $
  4. */
  5.  
  6. /****************************************************************
  7. *                                                               *
  8. *                    D E B U G   M A C R O S                    *
  9. *                                                               *
  10. ****************************************************************/
  11.  
  12. /*
  13.  * mydebug.h - #include this file sometime after stdio.h
  14.  * Set MYDEBUG to 1 to turn on debugging, 0 to turn off debugging
  15.  */
  16.  
  17. #ifndef MYDEBUG_H
  18. #define MYDEBUG_H
  19.  
  20.  
  21.  
  22. #if MYDEBUG
  23.  
  24. /*
  25.  * MYDEBUG User Options
  26.  */
  27.  
  28. /* Set to 1 to turn second level D2(bug()) statements */
  29. #define DEBUGLEVEL2 1
  30.  
  31. /* Set to a non-zero # of ticks if a delay is wanted after each debug message */
  32. #define DEBUGDELAY    0
  33.  
  34. /* Always non-zero for the DDx macros */
  35. #define DDEBUGDELAY   50
  36.  
  37. /* Set to 1 for serial debugging (link with debug.lib) */
  38. #define KDEBUG    1
  39.  
  40. /* Set to 1 for parallel debugging (link with ddebug.lib) */
  41. #define DDEBUG    0
  42.  
  43. #endif /* MYDEBUG */
  44.  
  45.  
  46. /* Prototypes for Delay, kprintf, dprintf. Or use proto/dos.h or functions.h. */
  47. #include <clib/dos_protos.h>
  48. void kprintf(UBYTE *fmt,...);
  49. void dprintf(UBYTE *fmt,...);
  50.  
  51. /*
  52.  * D(bug()), D2(bug()), DQ((bug()) only generate code if MYDEBUG is non-zero
  53.  *
  54.  * Use D(bug()) for general debugging, D2(bug()) for extra debugging that
  55.  * you usually won't need to see, DD(bug()) for debugging statements that
  56.  * you always want followed by a delay, and DQ(bug()) for debugging that
  57.  * you'll NEVER want a delay after (ie. debugging inside a Forbid, Disable,
  58.  * Task, or Interrupt)
  59.  *
  60.  * Some example uses (all are used the same):
  61.  * D(bug("about to do xyz. variable = $%lx\n",myvariable)); 
  62.  * D2(bug("v1=$%lx v2=$%lx v3=$%lx\n",v1,v2,v3)); 
  63.  * DQ(bug("in subtask: variable = $%lx\n",myvariable));
  64.  * DD(bug("About to do xxx\n"));
  65.  *
  66.  * Set MYDEBUG above to 1 when debugging is desired and recompile the modules
  67.  *  you wish to debug.  Set to 0 and recompile to turn off debugging.
  68.  *
  69.  * User options set above:
  70.  * Set DEBUGDELAY to a non-zero # of ticks (ex. 50) when a delay is desired.
  71.  * Set DEBUGLEVEL2 nonzero to turn on second level (D2) debugging statements
  72.  * Set KDEBUG to 1 and link with debug.lib for serial debugging.
  73.  * Set DDEBUG to 1 and link with ddebug.lib for parallel debugging.
  74.  */
  75.  
  76.  
  77. /* 
  78.  * Debugging function automaticaly set to printf, kprintf, or dprintf
  79.  */
  80.  
  81. #if KDEBUG
  82. #define bug kprintf
  83. #elif DDEBUG
  84. #define bug dprintf
  85. #else /* else changes all bug's to printf's */
  86. #define bug printf
  87. #endif
  88.  
  89. /*
  90.  * Debugging macros
  91.  */
  92.  
  93. //define id(ID) bug("%c%c%c%c", (ID>>24) & 0x0F, (ID>>16) & 0x0F, (ID>>8) & 0x0F, (ID>>0) & 0x0F
  94.  
  95. /* D(bug(   delays DEBUGDELAY if DEBUGDELAY is > 0
  96.  * DD(bug(  always delays DDEBUGDELAY
  97.  * DQ(bug(      (debug quick) never uses Delay.  Use in forbids,disables,ints
  98.  * The similar macros with "2" in their names are second level debugging
  99.  */
  100. #if MYDEBUG    /* Turn on first level debugging */
  101. #define D(x)  (x); if(DEBUGDELAY>0) Delay(DEBUGDELAY)
  102. #define DD(x) (x); Delay(DDEBUGDELAY)
  103. #define DQ(x) (x)
  104. #if DEBUGLEVEL2 /* Turn on second level debugging */
  105. #define D2(x)  (x); if(DEBUGDELAY>0) Delay(DEBUGDELAY)
  106. #define DD2(x) (x); Delay(DDEBUGDELAY)
  107. #define DQ2(x) (x)
  108. #else  /* Second level debugging turned off */
  109. #define D2(x) ;
  110. #define DD2(x) ;
  111. #define DQ2(x) ;
  112. #endif /* DEBUGLEVEL2 */
  113. #else  /* First level debugging turned off */
  114. #define D(x) ;
  115. #define DQ(x) ;
  116. #define D2(x) ;
  117. #define DD(x) ;
  118. #endif
  119.  
  120.  
  121. #endif /* MYDEBUG_H */
  122.  
  123.